package com.finals.finalsscreen.dialog;

import android.annotation.TargetApi;
import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.finals.finalsscreen.R;
import com.finals.finalsscreen.util.Util;

@TargetApi(19)
public class IncallDialog extends CommonDialog implements android.view.View.OnClickListener {

	View acceptView, denyView;

	public IncallDialog(Context context) {
		super(context);
		setContentView(R.layout.activity_dialog);
		InitWindow();
		InitView();
	}

	private void InitWindow() {
		Window mWindow = getWindow();
		mWindow.setWindowAnimations(android.R.anim.fade_in);
		mWindow.setType(WindowManager.LayoutParams.TYPE_TOAST);
		mWindow.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		mWindow.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
		mWindow.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
		mWindow.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
		if (android.os.Build.VERSION.SDK_INT >= 19) {
			mWindow.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
		}
	}

	private void InitView() {
		acceptView = findViewById(R.id.accept);
		acceptView.setOnClickListener(this);

		denyView = findViewById(R.id.deny);
		denyView.setOnClickListener(this);
	}

	@Override
	public void onClick(View view) {
		if (view.equals(acceptView)) {

		} else if (view.equals(denyView)) {
			Util.endPhone(mContext);
		}
	}

	@Override
	public void show() {
		try {
			super.show();
		} catch (SecurityException e) {
			Toast.makeText(mContext, "系统对话框权限被拒绝了", Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		}
	}
}
